from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-20 14:12:49.267141
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 20, Aug, 2021
Time: 14:12:54
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.7036
Nobs: 389.000 HQIC: -46.2571
Log likelihood: 4190.01 FPE: 5.66198e-21
AIC: -46.6206 Det(Omega_mle): 4.50566e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.435579 0.095774 4.548 0.000
L1.Burgenland 0.101347 0.049499 2.047 0.041
L1.Kärnten -0.116107 0.024560 -4.727 0.000
L1.Niederösterreich 0.163135 0.106994 1.525 0.127
L1.Oberösterreich 0.130318 0.105380 1.237 0.216
L1.Salzburg 0.287297 0.052055 5.519 0.000
L1.Steiermark 0.019278 0.068788 0.280 0.779
L1.Tirol 0.113347 0.054291 2.088 0.037
L1.Vorarlberg -0.115548 0.049048 -2.356 0.018
L1.Wien -0.011874 0.094615 -0.125 0.900
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.011415 0.223281 0.051 0.959
L1.Burgenland -0.049626 0.115399 -0.430 0.667
L1.Kärnten 0.034796 0.057258 0.608 0.543
L1.Niederösterreich -0.258934 0.249438 -1.038 0.299
L1.Oberösterreich 0.544750 0.245675 2.217 0.027
L1.Salzburg 0.315969 0.121358 2.604 0.009
L1.Steiermark 0.114621 0.160367 0.715 0.475
L1.Tirol 0.305413 0.126571 2.413 0.016
L1.Vorarlberg -0.010838 0.114347 -0.095 0.924
L1.Wien 0.004568 0.220578 0.021 0.983
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.248132 0.048655 5.100 0.000
L1.Burgenland 0.092152 0.025146 3.665 0.000
L1.Kärnten -0.003358 0.012477 -0.269 0.788
L1.Niederösterreich 0.229679 0.054355 4.226 0.000
L1.Oberösterreich 0.164540 0.053535 3.074 0.002
L1.Salzburg 0.035970 0.026445 1.360 0.174
L1.Steiermark 0.010444 0.034945 0.299 0.765
L1.Tirol 0.070378 0.027581 2.552 0.011
L1.Vorarlberg 0.056161 0.024917 2.254 0.024
L1.Wien 0.097088 0.048066 2.020 0.043
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185629 0.047424 3.914 0.000
L1.Burgenland 0.044984 0.024510 1.835 0.066
L1.Kärnten -0.007123 0.012161 -0.586 0.558
L1.Niederösterreich 0.127740 0.052980 2.411 0.016
L1.Oberösterreich 0.317568 0.052180 6.086 0.000
L1.Salzburg 0.101290 0.025776 3.930 0.000
L1.Steiermark 0.137606 0.034061 4.040 0.000
L1.Tirol 0.074574 0.026883 2.774 0.006
L1.Vorarlberg 0.055232 0.024287 2.274 0.023
L1.Wien -0.038187 0.046850 -0.815 0.415
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.213798 0.094828 2.255 0.024
L1.Burgenland -0.058026 0.049010 -1.184 0.236
L1.Kärnten -0.036008 0.024317 -1.481 0.139
L1.Niederösterreich 0.090237 0.105936 0.852 0.394
L1.Oberösterreich 0.182913 0.104338 1.753 0.080
L1.Salzburg 0.262861 0.051541 5.100 0.000
L1.Steiermark 0.079640 0.068108 1.169 0.242
L1.Tirol 0.123514 0.053755 2.298 0.022
L1.Vorarlberg 0.115126 0.048563 2.371 0.018
L1.Wien 0.029927 0.093680 0.319 0.749
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.024021 0.073945 0.325 0.745
L1.Burgenland 0.026612 0.038217 0.696 0.486
L1.Kärnten 0.050443 0.018962 2.660 0.008
L1.Niederösterreich 0.197680 0.082608 2.393 0.017
L1.Oberösterreich 0.353438 0.081362 4.344 0.000
L1.Salzburg 0.045391 0.040191 1.129 0.259
L1.Steiermark -0.001885 0.053110 -0.035 0.972
L1.Tirol 0.112401 0.041917 2.681 0.007
L1.Vorarlberg 0.061228 0.037869 1.617 0.106
L1.Wien 0.132235 0.073050 1.810 0.070
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186624 0.090158 2.070 0.038
L1.Burgenland 0.022622 0.046596 0.485 0.627
L1.Kärnten -0.057044 0.023120 -2.467 0.014
L1.Niederösterreich -0.115146 0.100719 -1.143 0.253
L1.Oberösterreich 0.187149 0.099200 1.887 0.059
L1.Salzburg 0.030089 0.049003 0.614 0.539
L1.Steiermark 0.299566 0.064754 4.626 0.000
L1.Tirol 0.493964 0.051107 9.665 0.000
L1.Vorarlberg 0.067647 0.046172 1.465 0.143
L1.Wien -0.112623 0.089066 -1.264 0.206
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163433 0.098119 1.666 0.096
L1.Burgenland -0.007035 0.050711 -0.139 0.890
L1.Kärnten 0.062899 0.025162 2.500 0.012
L1.Niederösterreich 0.195772 0.109613 1.786 0.074
L1.Oberösterreich -0.122285 0.107960 -1.133 0.257
L1.Salzburg 0.244970 0.053330 4.593 0.000
L1.Steiermark 0.153733 0.070472 2.181 0.029
L1.Tirol 0.050813 0.055621 0.914 0.361
L1.Vorarlberg 0.120785 0.050249 2.404 0.016
L1.Wien 0.140113 0.096931 1.445 0.148
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.491148 0.053241 9.225 0.000
L1.Burgenland -0.010910 0.027517 -0.396 0.692
L1.Kärnten -0.009497 0.013653 -0.696 0.487
L1.Niederösterreich 0.201059 0.059479 3.380 0.001
L1.Oberösterreich 0.258740 0.058581 4.417 0.000
L1.Salzburg 0.021033 0.028938 0.727 0.467
L1.Steiermark -0.022458 0.038240 -0.587 0.557
L1.Tirol 0.067500 0.030181 2.237 0.025
L1.Vorarlberg 0.058627 0.027266 2.150 0.032
L1.Wien -0.052768 0.052597 -1.003 0.316
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.018040 0.079449 0.136016 0.128675 0.043760 0.067918 0.002984 0.176763
Kärnten 0.018040 1.000000 -0.057274 0.129037 0.046518 0.067590 0.457847 -0.093636 0.097226
Niederösterreich 0.079449 -0.057274 1.000000 0.290653 0.088045 0.276131 0.012253 0.150746 0.251431
Oberösterreich 0.136016 0.129037 0.290653 1.000000 0.174008 0.292420 0.162691 0.117999 0.136863
Salzburg 0.128675 0.046518 0.088045 0.174008 1.000000 0.129322 0.055102 0.110714 0.051686
Steiermark 0.043760 0.067590 0.276131 0.292420 0.129322 1.000000 0.127163 0.088175 -0.023992
Tirol 0.067918 0.457847 0.012253 0.162691 0.055102 0.127163 1.000000 0.039566 0.119308
Vorarlberg 0.002984 -0.093636 0.150746 0.117999 0.110714 0.088175 0.039566 1.000000 -0.048152
Wien 0.176763 0.097226 0.251431 0.136863 0.051686 -0.023992 0.119308 -0.048152 1.000000